#ifndef _ROUTER_H_201_12_19
#define _ROUTER_H_201_12_19
/*#include "net.h"*/
#include "../platform/_platform_def.h"
class router
{
public:
	router(router_type routertype):_routertype(routertype)
	{
		
	}
	virtual ~router()
	{

	}
public:
	void init()
	{
		_client_cache_mgr.init();
		_server_cache_mgr.init();
	}
public:
	bool add_to_uid_cache(UID uid)
	{
		return _client_cache_mgr.add_to_uid_cache(uid);
	}
	void remove_from_uid_cache(UID uid)
	{
		_client_cache_mgr.remove_from_uid_cache(uid);
	}
	netcache* get_cache_from_uid(UID uid)
	{
		return _client_cache_mgr.get_cache_from_uid(uid);
	}
	bool add_to_fd_cache(SY_SOCKET fd,router_type rt = RT_CLIENT)
	{
		if(rt == RT_CLIENT)
			return _client_cache_mgr.add_to_fd_cache(fd,rt);
		else
			return _server_cache_mgr.add_to_fd_cache(fd,rt);
	}
	void remove_from_fd_cache(SY_SOCKET fd,router_type rt = RT_CLIENT)
	{
		if(rt == RT_CLIENT)
			return _client_cache_mgr.remove_from_fd_cache(fd);
		else
			return _server_cache_mgr.remove_from_fd_cache(fd);
	}
	netcache* get_cache_from_fd(SY_SOCKET fd,router_type rt = RT_CLIENT)
	{
		if(rt == RT_CLIENT)
			return _client_cache_mgr.get_cache_from_fd(fd);
		else
			return _server_cache_mgr.get_cache_from_fd(fd);
	}

	bool update_router_type(SY_SOCKET fd,router_type rt)
	{
		netcache * nc = NULL;
		if(rt == RT_CLIENT)
			 nc = _client_cache_mgr.get_cache_from_fd(fd);
		else
			nc = _client_cache_mgr.get_cache_from_fd(fd);
		if(nc)
		{
			nc->_type = rt;
			return true;
		}
		return false;
	}
	const int routertype()
	{
		return _routertype;
	}
public:
typedef CTemplateCacheManager<netcache,MAX_NUM,MAX_CACHE_SIZE_CLIENT> cache_mgr;
protected:

private:
	cache_mgr _client_cache_mgr;
	cache_mgr _server_cache_mgr;
	router_type _routertype;
};


#endif//_ROUTER_H_201_12_19